home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap5 / 5_3 / input_c / input.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-15  |  1.9 KB  |  109 lines

  1.  
  2. #include "parsehtm.h"
  3. #include <stdio.h>
  4.  
  5. /* If we don't already have a case insensitive string compare
  6.  * Make one
  7.  */
  8. #ifndef strcasecmp
  9.  
  10. int (strcasecmp)(const char *s1,const char *s2)
  11. {
  12.     int returnValue = 1;
  13.     
  14.     if((NULL != s1)&&(NULL != s2))
  15.     {
  16.         char test1,test2;
  17.         
  18.         for(;;++s1,++s2)
  19.         {
  20.             test1 = tolower(*s1);
  21.             test2 = tolower(*s2);
  22.             
  23.             if(test1 != test2)
  24.             {
  25.                 returnValue = 
  26.                     ((test1 < test2) ? -1:+1);
  27.                 break;
  28.             }
  29.             else if(test1 == '\0')
  30.             {
  31.                 returnValue = 0;
  32.                 break;
  33.             }
  34.         }
  35.     }
  36.     else if((NULL == s1)&&(NULL == s2))
  37.     {
  38.         returnValue = 0;
  39.     }
  40.     
  41.     return returnValue;
  42. }
  43.  
  44. #endif
  45.  
  46. void inputHandler(String ts,String as,String et,Dictionary td)
  47. {
  48.     String type = 0;
  49.     
  50.     /* Get the tags type */
  51.     type = dict_valueForKey(td,"TYPE");
  52.     
  53.     /* Update the tag string based on the type */
  54.     if(type && type->string)
  55.     {
  56.         if(!strcasecmp(type->string,"text"))
  57.         {
  58.             string_appendString(ts," :: text field");
  59.         }
  60.         else if(!strcasecmp(type->string,"password"))
  61.         {
  62.             string_appendString(ts," :: password field");
  63.         }
  64.         else if(!strcasecmp(type->string,"checkbox"))
  65.         {
  66.             string_appendString(ts," :: checkbox");
  67.         }
  68.         else if(!strcasecmp(type->string,"radio"))
  69.         {
  70.             string_appendString(ts," :: radio");
  71.         }
  72.         else if(!strcasecmp(type->string,"submit"))
  73.         {
  74.             string_appendString(ts," :: submit");
  75.         }
  76.         else if(!strcasecmp(type->string,"hidden"))
  77.         {
  78.             string_appendString(ts," :: hidden field");
  79.         }
  80.     }
  81. }
  82.  
  83. void main(int argc, char *argv[])
  84. {
  85.     String output;
  86.     
  87.     /* Always call this first */
  88.     initializeHtmlParsingLibrary();
  89.     
  90.     /* Register the handler */
  91.     dict_setValueForKey(handlerDict,"INPUT", inputHandler);
  92.  
  93.     /* Parse the html file */
  94.     output = parseHtml("inp_c.htm");
  95.     
  96.     /* Send the html to the client */
  97.     if(output && output->string)
  98.     {
  99.         printf("Content-type: text/html\n\n");
  100.         fwrite(output->string,sizeof(char),strlen(output->string),stdout);
  101.         printf("\n");
  102.         
  103.         string_free(output);
  104.     }
  105.     
  106.     exit(0);
  107. }
  108.  
  109.